package com.example.test;

import com.example.config.MySpringConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Description: 测试打印 Spring 容器中的对象
 * spring 容器中对象默认是单例的
 * @Author: mingtian
 * @CreateDate: 2019/12/6 10:49
 * @Version: 1.0
 */
public class BeanTest04 {

    /**
     * 加载配置类
     */
    private static AnnotationConfigApplicationContext applicationContext;

    public static void main(String[] args) {
        applicationContext = new AnnotationConfigApplicationContext(MySpringConfig.class);

        //spring 容器中 bean 数量
        int beanDefinitionCount = applicationContext.getBeanDefinitionCount();
        //打印 Spring 容器中已经注入的对应
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        System.out.println("bean.size:" + beanDefinitionCount);
        for (String s : beanDefinitionNames) {
            System.out.println("bean:" + s);
        }
    }
}